/**************************************************************************
*Copyright (C) 2025 公司名, Inc.(Gmbh) or its affiliates.
*
*All Rights Reserved.
*
*@file bsp_led.h
*
*@par dependencies
* - stdio.h
* - stdint.h
* - cmsis_os2.h
* - FreeRTOS.h
* - queue.h
* - stm32f4xx_hal.h
* - gpio.h
*
*@author fhc | 部门 | 公司 
*
*@brief Provide the HAL APIs of Led and corresponding options.
*
*Processing flow:
*
*call directly.
*
*@version V1.0 2025-11-07
*
*@note 1 tab == 4 spaces!
*
**************************************************************************/

//******************************** Includes *********************************//
#include "bsp_led.h"                      

//******************************** Includes *********************************//

//******************************** Defines **********************************//

osThreadId_t  g_led_TaskHandle = NULL;     
QueueHandle_t g_led_queue      = NULL;      /* the queue of th key  */

const osThreadAttr_t g_led_Task_attributes = {
    .name = "led_Task",
    .stack_size = 128 * 4,
    .priority = (osPriority_t) osPriorityHigh,
  };
//******************************** Defines **********************************//

//******************************** Declaring ********************************//
/**
 * @brief sthe opearation of LE .
 * 
 * Steps:
 *  1.doing the specific operations
 *  
 * @param[in] const led_operation_t				:  the opearation of LED
 * 
 * @return led_status_t : Status of the function.
 * 
 * */
led_status_t led_on_off(const led_operation_t led_operation)
{
	led_status_t ret=LED_OK;
	if( LED_ON 		== led_operation)
	{
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_RESET);
		return ret;
	}
	if( LED_OFF     == led_operation)
	{
		HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,GPIO_PIN_SET);
		return ret;		
	}
	if( LED_TOGGLE  == led_operation)
	{
		HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
		return ret;		
	}
	if( LED_BLINK_3 == led_operation)
	{
		for(int i=0;i<6;i++)
		{
			HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
			vTaskDelay(1000);
		}
		return ret;	
	}
	return LED_ERROR;
}
/**
 * @brief  key_task_func for thread to run.
 * 
 * Steps:
 *  1.doing the specific operations
 *  
 * @param[in] void										
 * @return None
 * 
 * */
void led_task_func(void *argument)
{   
	BaseType_t               xStatus;
	led_operation_t    led_operation;
    printf("led_task_func is start \r\n"); 
	/*Create a queue capable of  containing
     10 key_press_status_t values.
    */
	g_led_queue = xQueueCreate( 10, 
                            sizeof( led_operation_t ) );
	if( NULL == g_led_queue   )
	{
		// Queue was not created and must not be used.
    	printf("g_led_queue was not created\r\n");
	}
    for(;;)
    {
    	xStatus = xQueueReceive( g_led_queue, & led_operation, portMAX_DELAY);
    	if( pdPASS == xStatus   )
    	{
			led_on_off(led_operation);
	    	printf("led operation sucess\r\n");
    	} 
    	osDelay(1000);       
    }
}
//******************************** Declaring ********************************//

